import {reqShowAllSongList,reqShowAllSinger} from "@/api";

const state={
    songList:[],
    singer:[],
    loginInfo:true,
    avator:'',
    userId:'',
    userName:''
}
const mutations={
    GETALLSONGLIST(state,songList){
        state.songList=songList
    },
    GETALLSINGER(state,singer){
        state.singer=singer
    },
    LOGININFO(state,loginInfo){
        state.loginInfo=loginInfo
    },
    AVATOR(state,avator){
        state.avator=avator
    },
    USERID(state,userId){
        state.userId=userId
    },
    USERNAME(state,userName){
        state.userName=userName
    }
}
const actions={
 async getAllSongList({commit}){
    let result= await reqShowAllSongList()
     if (result.code==10000){
         commit('GETALLSONGLIST',result.data)
     }else{
        await Promise.reject(new Error('fail'))
     }
  },
    async getAllSinger({commit}){
        let result= await reqShowAllSinger()
        if (result.code==10000){
            commit('GETALLSINGER',result.data)
        }else{
            await Promise.reject(new Error('fail'))
        }
    }
}
const getters={
    getAllSongList(state){
        let songList= state.songList.slice(0,10)
        return songList
    },
    getAllSinger(state){
        let singer= state.singer.slice(0,10)
        return singer
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}
